package com.shop.cereshop.business.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.cereshop.business.annotation.NoRepeatSubmit;
import com.shop.cereshop.business.annotation.NoRepeatWebLog;
import com.shop.cereshop.business.service.buyer.CereBuyerShopCouponService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.billing.bo.CereShopBillingBo;
import com.shop.cereshop.commons.domain.buyer.CereBuyerShopCoupon;
import com.shop.cereshop.commons.domain.buyer.bo.CereBuyerShopCouponBo;
import com.shop.cereshop.commons.domain.buyer.vo.CereBuyerShopCouponStatVo;
import com.shop.cereshop.commons.domain.buyer.vo.CereBuyerShopCouponVo;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import com.shop.cereshop.commons.utils.GsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 用户领取优惠券管理
 */
@RestController
@RequestMapping("buyerShopCoupon")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "BuyerUserController")
@Api(value = "用户领取优惠券模块", tags = "用户领取优惠券模块")
public class CereBuyerShopConponController {

    @Autowired
    private CereBuyerShopCouponService cereBuyerShopCouponService;


    /**
     * 查询用户领取优惠券记录
     */
    @PostMapping("/queryList")
    @ApiOperation(value = "查询用户领取优惠券记录")
    public Result<Page<CereBuyerShopCouponVo>> queryList(@RequestBody CereBuyerShopCouponBo bo, HttpServletRequest request)  throws CoBusinessException {
        PageHelper.startPage(bo.getPage(),bo.getPageSize());
        List<CereBuyerShopCouponVo> cereBuyerShopCouponVos = cereBuyerShopCouponService.queryList(bo);
        PageInfo<CereBuyerShopCouponVo> pageInfo = new PageInfo<>(cereBuyerShopCouponVos);
        Page<CereBuyerShopCouponVo> tPage = new Page<CereBuyerShopCouponVo>( pageInfo.getList(),pageInfo.getTotal());
        return new Result(tPage,CoReturnFormat.SUCCESS);
    }

    /**
     * 店铺优惠券领取统计
     */
    @GetMapping("/stat")
    @ApiOperation(value = "店铺优惠券领取统计")
    public Result<CereBuyerShopCouponStatVo> stat(Long shopCouponId, HttpServletRequest request)  throws CoBusinessException {

        CereBuyerShopCouponStatVo stat = cereBuyerShopCouponService.stat(shopCouponId);
        return new Result(stat,CoReturnFormat.SUCCESS);
    }

}
